all: aes_cbc aes_col des_cfb decrypt_aes_cbc.class pwenc

decrypt_aes_cbc.class:	decrypt_aes_cbc.java
	@echo make decrypt_aes_cbc.class
	@javac decrypt_aes_cbc.java
	@echo done

aes_col: crypter.c crypter_aes_cbc.c
	@echo make aes_col
	@gcc -static -DDIFF_COLUMN_IV -o aes_col crypter.c crypter_aes_cbc.c parseIPV4.c /usr/lib64/libcrypto.a /usr/lib64/libssl.a /usr/lib64/libdl.a
	@tar cpf aes_col.tar aes_col
	@cp -p install.tpl installcol.sh
	@cat aes_col.tar >> installcol.sh
	@sed -i 's/%NUMLINES%/'`cat install.tpl | wc -l`'/g; s/%BINNAME%/aes_col/g' installcol.sh
	@chmod +x installcol.sh
	@cp -p installcol.sh ../../../install/
	@echo done
	
aes_cbc: crypter.c crypter_aes_cbc.c
	@echo make aes_cbc
	@gcc -static -o aes_cbc crypter.c crypter_aes_cbc.c parseIPV4.c /usr/lib64/libcrypto.a /usr/lib64/libssl.a /usr/lib64/libdl.a
	@tar cpf aes_cbc.tar aes_cbc
	@cp -p install.tpl installaes.sh
	@cat aes_cbc.tar >> installaes.sh
	@sed -i 's/%NUMLINES%/'`cat install.tpl | wc -l`'/g; s/%BINNAME%/aes_cbc/g' installaes.sh
	@chmod +x installaes.sh
	@cp -p installaes.sh ../../../install/
	@echo done

des_cfb: crypter.c crypter_des_cfb.c
	@echo make des_cfb
	@gcc -static -o des_cfb crypter.c crypter_des_cfb.c parseIPV4.c /usr/lib64/libcrypto.a /usr/lib64/libssl.a /usr/lib64/libdl.a
	@tar cpf des_cfb.tar des_cfb
	@cp -p install.tpl installdes.sh
	@cat des_cfb.tar >> installdes.sh
	@sed -i 's/%NUMLINES%/'`cat install.tpl | wc -l`'/g; s/%BINNAME%/des_cfb/g' installdes.sh
	@chmod +x installdes.sh
	@cp -p installdes.sh ../../../install/
	@echo done

pwenc:	pwenc.c crypter_aes_cbc.c
	@echo make pwenc
	@gcc -static -o pwenc pwenc.c crypter_aes_cbc.c /usr/lib64/libcrypto.a /usr/lib64/libssl.a
	@tar cpf pwenc.tar pwenc
	@cp -p install.tpl installpwe.sh
	@cat pwenc.tar >> installpwe.sh
	@sed -i 's/%NUMLINES%/'`cat install.tpl | wc -l`'/g; s/%BINNAME%/pwenc/g' installpwe.sh
	@chmod +x installpwe.sh
	@cp -p installpwe.sh ../../../install/
	@echo done

clean:
	@echo cleanup
	@rm -f aes_cbc aes_col des_cfb crypter.o crypter_aes_cbc.o parseIPV4.o crypter_des_cfb.o aes_cbc.tar aes_col.tar des_cfb.tar
	@rm -f pwenc pwenc.o pwenc.tar
	@rm -f temp.key .pwenc.key psw.txt psw.enc psw.dec
	@rm -f installpwe.sh installdes.sh installaes.sh installcol.sh
	@rm -f decrypt_aes_cbc.class
	@rm -f test.encrypted.aes_cbc test.decrypted.aes_cbc test.encrypted.des_cfb test.decrypted.des_cfb
	@echo done
test:
	@tr -dc '\16-\177' < /dev/urandom | head -c 16 >temp.key
	@tr -dc A-Za-z0-9 < /dev/urandom | head -c 16 >.pwenc.key
	@./aes_cbc Y 12 ./temp.key encrypt h1 h6 h7 <test.txt >test.encrypted.aes_cbc
	@./aes_cbc Y 12 ./temp.key decrypt h1 h6 h7 <test.encrypted.aes_cbc >test.decrypted.aes_cbc
	@cmp test.txt test.decrypted.aes_cbc
	@echo original and decripted files are identical. aes_cbc is OK.
	@./aes_col Y 12 ./temp.key encrypt h1 h6 h7 <test.txt >test.encrypted.aes_col
	@./aes_col Y 12 ./temp.key decrypt h1 h6 h7 <test.encrypted.aes_col >test.decrypted.aes_col
	@cmp test.txt test.decrypted.aes_col
	@echo original and decripted files are identical. aes_col is OK.
	@java decrypt_aes_cbc `awk -F "\t" '{if(NR==5) print $1}' test.encrypted.aes_cbc` >/dev/null
	@echo aes_cbc java decripter is OK.
	@./des_cfb Y 12 ./temp.key encrypt h1 i6 h7 <test.txt >test.encrypted.des_cfb
	@./des_cfb Y 12 ./temp.key decrypt h1 i6 h7 <test.encrypted.des_cfb >test.decrypted.des_cfb
	@cmp test.txt test.decrypted.des_cfb
	@echo original and decripted files are identical. des_cfb is OK.
	@tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 >psw.txt
	@echo original psw: `cat psw.txt`
	@./pwenc enc <psw.txt >psw.enc
	@./pwenc dec <psw.enc >psw.dec
	@cmp psw.txt psw.dec
	@echo original passwrod identical to decrypted : `cat psw.dec`
	@echo done

install: aes_cbc des_cfb pwenc decrypt_aes_cbc.class
	@./installpwe.sh
	@./installaes.sh
	@./installcol.sh
	@./installdes.sh

commit:
	svn commit -m "" ../../../install/installpwe.sh
	svn commit -m "" ../../../install/installaes.sh
	svn commit -m "" ../../../install/installdes.sh
	svn commit -m "" ../../../install/installcol.sh
